package org.icress.fusion.moc

import org.icress.fusion.shiro.User

class Tc {//班组完成情况
    
    def tcService
	
    Tb tb//工单
	Integer tc001//实际投入人力
	Integer tc002//完成量
	Date tc003//工单开始时间
	Date tc004//工单结束时间
	BigDecimal tc005//实际生产工时
	BigDecimal tc016//单位标准工时(ERP)
    String tc020//生产线-工作中心
	Ti ti//单位标准工时代号
	BigDecimal tc017//单位标准工时(对照表)
    BigDecimal standardWorkForce//单位标准工时

    BigDecimal tc022//正常换线


    //公式
    BigDecimal tc011//标准产出工时
    BigDecimal tc012//作业效率
    BigDecimal tc013//生产效率

    BigDecimal tc018//非生产总工时
    BigDecimal tc010//实际生产总工时
    BigDecimal tc021//报表总工时
    
	Date dateCreated//创建日期
	User createdBy//创建人
	Date lastUpdated//最后修改日
	User lastModifiedBy//上次修改人
	User owner//所有人
	
	static belongsTo = [tb:Tb]
	static hasMany = [tgs:Tg]
	
    static constraints = {
        tb(nullable:false)
		tc001(min : 1i, nullable:false)
		tc002(min : 1i, nullable:false, validator: { val, obj -> 
            def old_tc002 = obj.getPersistentValue('tc002')
            def sum_tc002 = obj.tb.tcs*.tc002.sum()
                sum_tc002 = sum_tc002?sum_tc002:0
            if(old_tc002? sum_tc002 > obj.tb.tb004 * obj.tb.tb012 : val > obj.tb.tb004 * obj.tb.tb012 - sum_tc002)
                return ['tc.invalid.maxvalue.message', val, old_tc002, sum_tc002, obj.tb.tb004 * obj.tb.tb012]
            else
                return true
        })
        tc003(nullable:false, blank:false, validator:{val, obj ->
            return obj.tcService.validateLockdate(val)
        })
        tc004(nullable:false, blank:false, validator:{val, obj ->
            return val > obj.tc003
        })
		tc005(nullable:true, scale:6)
		tc016(nullable:true, scale:6)
        tc011(nullable:true, scale:6)
        tc012(nullable:true, scale:4)
        tc013(nullable:true, scale:4)
		ti(nullable:true)
		tc017(nullable:true,min : new BigDecimal(0), scale:6)
        tc020(nullable:true, blank:false, maxSize:20)
        tc022(nullable:false, min : new BigDecimal(0), scale:6)
        tc010(nullable:true, scale:6)
        tc018(nullable:true, scale:6)
        tc021(nullable:true, scale:6)
        standardWorkForce(nullable:true, scale:6)
    }
	
	static mapping = {
		table 'MOC$TC'
		tgs cascade:"all-delete-orphan", sort:"td", batchSize: 100
        autoTimestamp true
	}

}
    
